/**
 * 
 */
package com.wodsy.phoenix.apps.cms.homepage.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.model.IdxNewGoodsRecommended;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageBannerService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageCustomizePicService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageHotGoodsService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageNewGoodsService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageShopRecService;

/**
 * @author bryan
 *
 */
@RequestMapping("/cmsNewGoods")
@Controller
public class CmsHomePageIndexNewGoodsController {
	private Logger logger = LoggerFactory.getLogger(CmsHomePageIndexNewGoodsController.class);
	@Autowired
	private CmsHomePageBannerService cmsHomePageBannerService;
	@Autowired
	private CmsHomePageCustomizePicService cmsHomePageCustomizePicService;
	//private CmsHomePageGoodsStatusService.java
	@Autowired
	private CmsHomePageHotGoodsService cmsHomePageHotGoodsService;
	@Autowired
	private CmsHomePageNewGoodsService cmsHomePageNewGoodsService;
	@Autowired
	private CmsHomePageShopRecService cmsHomePageShopRecService;

	/**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    @RequestMapping(value = { "/index","/" }, method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
        return "/newGoods";
    }
    
	@RequestMapping(value = {"/newGoodsCreatePage"},method = RequestMethod.GET)
	public String toNewGoodsCreatePage(){
		return "new";
	}
	

	@RequestMapping(value = {"/goods/{rid}"},method = RequestMethod.GET)
	public String show(@PathVariable String rid){

		return "view";
	}
    
    
    
    
    /**
	 * 增加一条goods
	 */
    @RequestMapping(value = "/addOneNewGoods", method = RequestMethod.POST)
    @ResponseBody
    public void addOneNewGoods(IdxNewGoodsRecommended tNewGoodsRecommended){
		/*CmsContentStatus status = CmsContentStatus.ISONLINE;
		IdxNewGoodsRecommended tNewGoodsRecommended = new IdxNewGoodsRecommended();
		tNewGoodsRecommended.setGoodsId(1);
		tNewGoodsRecommended.setGoodsName("商品名称");
		tNewGoodsRecommended.setGoodsPic("http://www.google.com");
		
		tNewGoodsRecommended.setOfflineTime(new Date());
		tNewGoodsRecommended.setOnlineTime(new Date());
		
		tNewGoodsRecommended.setStatus(status);
		tNewGoodsRecommended.setWeight(1);
		
		tNewGoodsRecommended.setCreateTime(new Date());*/
		
		cmsHomePageNewGoodsService.addNewGoodsRecommended(tNewGoodsRecommended);
	}
	/**
	 * 获取一条goods信息
	 */
    @RequestMapping(value = "/getOneNewGoods/{rgoodsId}", method = RequestMethod.GET)
    @ResponseBody
    public IdxNewGoodsRecommended getOneNewGoods(@PathVariable Integer rgoodsId){
		
		IdxNewGoodsRecommended goods = cmsHomePageNewGoodsService.get(rgoodsId);
		
		return goods;
	}
	/**
	 * 修改一条goods信息
	 */
    @RequestMapping(value = "/updateOneNewGoods", method = RequestMethod.POST)
    @ResponseBody
    public void updateOneNewGoods(IdxNewGoodsRecommended goodsR){
    	goodsR.setUpdateTime(new Date());
		cmsHomePageNewGoodsService.updateNewGoodsRecommended(goodsR);//.update(goodsR);
	}
	/**
	 * 根据搜索条件查询goodsList
	 */
    @RequestMapping(value = "/getAllNewGoodsByOrder", method = RequestMethod.POST)
    @ResponseBody
    public Pager<IdxNewGoodsRecommended> getAllNewGoodsByOrder(int pageSize,int pageNo,IdxNewGoodsRecommended goodsreq){
		Pager<IdxNewGoodsRecommended> newGoodsRec = new Pager<>();
		newGoodsRec.setPageSize(pageSize);
		newGoodsRec.setPageNo(pageNo);
		
		Pager<IdxNewGoodsRecommended> picPager = cmsHomePageNewGoodsService.searchNewGoodsRecByOrder(newGoodsRec, goodsreq);
	
		return picPager;
	}
	/**
	 * 更新pic状态
	 */
    @RequestMapping(value = "/updatePicNewGoodsStatus", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicNewGoodsStatus(Integer rgoodId,Integer status){
		cmsHomePageNewGoodsService.updateGoodsRecommendedStatus(rgoodId, status);
	}
	
	/**
	 * 更新picList状态
	 */
    @RequestMapping(value = "/updatePicNewGoodsStatusList", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicNewGoodsStatusList(Integer[] list,Integer status){
		cmsHomePageNewGoodsService.updateGoodsRecommendedStatus(list, status);
	}
}
